/////precompiled////////
#include "precompiled.h"
////////////////////////


#include "prs_FrmDouble.h"
using namespace prs;

/*****************************
// TEventsCtrl ////////////////////////////////////////////////////////////////

//
void TEventsCtrl::TEvents_BeforeChangeValue(TChangeValue &Param)
{
  //Param.NewVal = "newVal";
  TEvents::TEvents_BeforeChangeValue(Param);
}

//
void TEventsCtrl::TEvents_AfterChangeValue(TChangeValue &Param)
{
  TEvents::TEvents_AfterChangeValue(Param);
}
*************************************/
// TNodeFrmStringControl //////////////////////////////////////////////////////

//
bool TNodeFrmDoubleControl::UpdateValue(svl::TString V)
{
  if (frm::control::TDouble::UpdateValue(V)) {
	node.Value = V.ConvertToDouble();
    return true;
  }
  return false;
}

// TNodeFrmDoubleControl /////////////////////////////////////////////////////////////

//
TNodeFrmDoubleControl *TNodeFrmDouble::BuildControl(
  frm::control::TPanel *ParentControl
)
{
  TNodeFrmDoubleControl *P = Control.GetValue();

  if (!P || &P->GetWindow() != &ParentControl->GetWindow()) {
    delete P; 
    P = new TNodeFrmDoubleControl(ParentControl->GetWindow(),*this);
    Control.SetValue(P);
    ParentControl->AddChildLast(P,false);

    P->SetValue(value);
  	P->SetPrecision(precision);
    P->SetEnableEdit( EnEdit.GetValue() );
  }
  
  return P;
}

//
void TNodeFrmDouble::TNode_SetPropDoubleValue(TAttrDoubleBase &Attr,double V) { 
  if (&Attr == &Value) { 
    value = V;
    updateValueInControl(); 
    return;
  }
  TNodeFrmControl::TNode_SetPropDoubleValue(Attr,V);
}

//
double TNodeFrmDouble::TNode_GetPropDoubleValue(TAttrDoubleBase &Attr) { 
  if (&Attr == &Value) { 
    return value;
  }
  return TNodeFrmControl::TNode_GetPropDoubleValue(Attr);
}

//
void TNodeFrmDouble::TNode_SetPropIntegerValue(TAttrIntegerBase &Attr,int P) { 
  if (&Attr == &Precision) { 
    precision = P;
    updateValueInControl(); 
    return;
  }
  TNodeFrmControl::TNode_SetPropIntegerValue(Attr,P);
}

//
int TNodeFrmDouble::TNode_GetPropIntegerValue(TAttrIntegerBase &Attr) { 
  if (&Attr == &Precision) { 
    return precision;
  }
  return TNodeFrmControl::TNode_GetPropIntegerValue(Attr);
}


//
void TNodeFrmDouble::updateValueInControl() { 
  TNodeFrmDoubleControl *P = Control; 
  TNodeUseTemplateParam::setValueFromBindAttr(Value,P);

  if (svl::TLocksStack::IsTop(St,P)) { 
    return;
  }
  svl::TLocksStack Push(St,P);

  if (P) { 
    frm::control::TPanel::TBeginPaint BeginPaint(P);
    P->frm::control::TDouble::UpdateValue(value);
	P->frm::control::TDouble::SetValue(value);
  }
}
// TNodeFrmDouble /////////////////////////////////////////////////////////////

// TRuleFrmDouble /////////////////////////////////////////////////////////////

//
TRuleFrmDouble::TRuleFrmDouble(
  snt::text::TContext &Context,
  svl::TVariant &VParentNode,
  TRuleFrmChildrenBase &RFrmChildren,
  TRuleSetNodeIdOptionally &RSetNodeIdOptionally,
  TRuleSetAttrValue &RSetAttrValue,
  TRuleSetStyle &RStyle
)
:vParentNode(VParentNode)
{
  snt::TFVoid F;
  TFuncNewNodeIntoAttrOldChildren FNewNode;
  snt::TReturn Return;
  snt::text::TIdent I(Context);
  snt::text::TSequence T(Context);
  snt::text::TString S(Context);
  sntText::TDouble D(Context);
  snt::text::TKeyword K(Context);

  this->Name(GetClassName()).Local(vParentNode)
  | K.New("double") & FNewNode.New(vParentNode,TNodeFrmDouble()) 
    & RSetNodeIdOptionally.New()
    & RAttr.New() 
    & Return.New()
  ;

  RAttr.Name(GetClassName() + "[RAttr]")
  | T.New("(") 
    & RAttr1.New() & RFrmChildren.New() 
    & T.New(")") & Return.New()
  | Return.New()
  ;

  RAttr1.Name(GetClassName() + "[RAttr1]")
  | AAttr1.New()
  ;
  AAttr1.Name(GetClassName() + "[AAttr1]")
  | RSetAttrValue.New(
      VParentNode,
      TRuleSetAttrValue::TAttrs()
       .Add(attrName_Value ,this,&TRuleFrmDouble::FSetParamDouble)
	   .Add(attrName_Precision ,this,&TRuleFrmDouble::FSetParamPrecision)
       .Add(attrName_EnEdit,this,&TRuleFrmDouble::FSetParamBool)
    )
    & AAttr1.New()
  | RStyle.New() & AAttr1.New()
  | Return.New()
  ;

}
